package com.hylanda.pb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hylanda.pb.entity.PBLocal;
import com.hylanda.pb.model.PBLocalQo;
import com.hylanda.pb.service.PBLocalService;

/**
 * http://10.80.221.141:8080/reports/powerbi/test141?rs:embed=true&rv:DocMapMode=Hidden&rv:DockToolBar=Bottom
* @author zhangy
* @E-mail:blackoon88@gmail.com 
* @qq:846579287
* @version 创建时间：2018年3月14日 下午3:12:40 
* note
 */
@Controller
@RequestMapping("/pblocal")
public class PBLocalController {
    public static Logger logger = LoggerFactory.getLogger(PBLocalController.class);

    @Autowired
    private PBLocalService pBLocalService;
    private static final String prefix = "pb/";
    @RequestMapping("/index")
    public String index() throws Exception{
        return prefix+"pblocal/index";
    }

//    @RequestMapping(value="/{name}")
//    public String show(ModelMap model,@PathVariable Long name) {
//    	//http://10.80.221.141:8080/reports/powerbi/test141?rs:embed=true&rv:DocMapMode=Hidden&rv:DockToolBar=Bottom
//        return prefix+"reportmodel/show";
//    }
  @RequestMapping(value="/reports/powerbi/{name}")
  public String showHtml(HttpServletRequest request,
			HttpServletResponse response) {
//	  String method = request.getMethod();
      String queryString = request.getQueryString();
      String requestURI = request.getRequestURI();
      StringBuilder requestUrl = new StringBuilder(requestURI.replace("/pblocal", ""));
      if (queryString != null) {
          requestUrl.append("?").append(queryString);
      }
	  String path ="redirect:" + requestUrl.toString();
//	  System.out.println(path);
      return path;
  }
    @RequestMapping(value = "/list")
    @ResponseBody
    public Page<PBLocal> getList(PBLocalQo pBLocalQo) {
        try {
            return pBLocalService.findPage(pBLocalQo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
